% FUNCTION: haarscale(i,j)
% Input: two integers i and j 
% Output: a vector y containing the function values of 
%         the ij:th normalized Haar scaling function on the interval [-1,2].
% ----------------------------------------------------------------
% Given an integer j=0,1,2,... representing the vector space V^j, and
% an integer i=0,1,...,2^(j-1) representing translation, the function
% returns a vector with function values of the normalized Haar scaling
% function on the interval [-1,2]. If you want to plot this function, 
% use the function "haargrid(v)".
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function y=haarscale(i,j)

y=zeros(3000,1);   % 3000 is chosen to give a suitable resolution.

support_start = ceil(1000*i/2^j)+1;   % Gives vector indices for where the
support_end = floor(1000*(1+i)/2^j);  % support of the function starts/end.

for k=1000+support_start:1000+support_end
   y(k) = 1;
end

norm_factor = sqrt(2^j);    % Normalizing factor w.r.t. the L^2-norm.
y = norm_factor*y;